// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'

import VueWechatTitle from 'vue-wechat-title'
import AwesomePicker from 'vue-awesome-picker'
import 'swiper/dist/css/swiper.min.css'
import FastClick from 'fastclick'
import Cookie from 'js-cookie'
import global from '../config/global'// 引用全局变量文件
Vue.prototype.GLOBAL = global// 挂载到Vue实例上面

Vue.config.productionTip = false
Vue.use(VueWechatTitle)
Vue.use(AwesomePicker)

import router from './router'
router.beforeEach((to, from, next) => {
  const token = Cookie.get('token')
  const userInfo = Cookie.get('userInfo')
  const user = JSON.parse(userInfo || '{}')
  // let ua = window.navigator.userAgent.toLowerCase()
  if (token) {
    next()
  } else {
    if (to.matched.some(record => record.meta.requireAuth)) {
      Cookie.set('backRedirectUrl', to.fullPath)
      next('/login')
    } else {
      next()
    }
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  render: (h) => h(App)
})

FastClick.attach(document.body)
